Updated code to MVC structure