refactor copyfrom, optimize code