Added the logic to the controller.
Finished the implementation.
ref #6