refactored with constructor function