Refactored - much better & simpler.
Testsuite fixed to adjust to refactoring.