Restructure to a more MVC design