refactored copy code.