Code cleanup

I took the liberty to go over the code and fix some issues, mostly stylistic.

Noticed that I had to fix up some tests that relied on the order of elements in keyword lists. A more fundamental change would be to convert keyword lists to maps where it makes sense, at least in the tests to make them more robust to implementation changes.