Refactor and organize code.