refactored. code organization