refactoring to fit MVC architecture