refactor to make code more modular