Moved the logic from the view (that should not be there) to the controller (where it better fits)