Refactored code into MVC framework