Refactoring...
Final refactoring.
Fixes unit test failures