Refactor to be more modular