Initial refactoring to comply with MVC model