Separated out the model code from the gui code