Controlling internal stress of deposited layers