updated the code to follow MVC