refactored the code to be modular