fixed copy function and added some tests to verify it works properly