added fields to the toCopyFrom function and some minor refactoring