refactored the logic to be in the model instead of the view