Refactor code to MVC