Move logic from the view (bad!) to the controller