Fix failing test.
Some refactoring.