Fixing error with copyObj function