Reorganized the code to be more MVC