Cleaned the code and made things more modular.