Major refactoring to separate the model from the view