Minor code touchups

This pull request contains a couple of minor changes to the code, mostly stylistic, partly changing subtle bugs. 

Each logical change is contained in its own commit.