Moved logic from view (old project) to controller.