further refactored code