Refactor to more modular codebase