Lots of minor code tidy-ups

And add a few more tests for @commutative