refactoring for better MVC