Refactoring to adhere to mvc architecture principle