refactored code for modularity