Charge density wave effects, structural effects and charge transfer in the layered compound TaS2