fully refactored code