Refactor and clean up codebase.