Refactor

First attempt at a refactor.  Much more to go.