Reorganized code to be more modular.