refactoring Controller code.