Various small code cleanups.
Merge pull request #2817 from thedax/master

Various code cleanups.