moving conditions from view to controller