Move logic from view to controller