Refactoring the test code a little bit to enable adding more scenarios

And some general cleanup.