Lots of code cleanup.  Trying to refactor and document