Cleanup

Mostly Coverity-inspired code cleanups (nothing too serious).