refactoring so that objects are initialized in the right order