CJ - Moved some logics to the controller.