Extensive refactoring and simplification. All unit tests OK.
Extensive refactoring and simplification. All unit tests OK.