Remodularization of the entire model.

Remodularized the model, so it now calls a series of functions to
perform the various tasks.  Will add a few more functions for some
low-level repeated code, but close to being done.