wrote copy function