Changed the code to be MVC appliant