refactored constructor function