Added tests for controller & refactored controller.