refactor Copy function