Fixed a few bugs found with static checking.
Merge origin/master
Slight formatting fix.