moved logic to controller from view