Some simplifications in implementation; tests pass but be wary of unexpected changes.