move logic from view to controller