Refactor

Phew!  Finally the refactor is complete.