refactored and added test case for controller