completed refactored code