refactored to follow more of MVC architecture