refactored code organization