Yet another big refactor.  Hopefully this is the last.