final (refactored code)