Clean up some implementation and style issues

This is a bit of a grab bag of (subjective) improvements, but hopefully some of them are useful.