moved logic from view to controller