Rewrote copyLamVal iteratively.