make copy routine more efficient