More refactoring and updated tests to reflect current status.