restructuring of the code and work on the copy function