Refactored to have a model object. Pulled a lot of code out of the tableviewcontroller into the model object.