refactoring to mvc pattern