More refactoring/testing based on updated design.