Various code cleanups

Fixing some code issues found by Scrutinizer  (and testing it's interface).