Modified controller to make easier to test and added test cases