partial refactoring to better reflect MVC patterns