refactor code to make it modular