Refactor for MVC pattern