Moved logic from the view and into the model where it belongs.