General function for copying object properties