Code cleanup

This pull requests contains a number of clean-ups. They don't change any behavior -- with the exception of 79f2f7a, which fixes some unit tests.