refactored code to be MVC