Working deep copy implementation