Refactor code into more modular components