refactored code structure