Changed code layout to make it more MVC