Refactor code to be more modular and consistent.