Fixed for bugs found via Coverity
Merge pull request #122 from litghost/coverity_fixes

Fixes for bugs found via Coverity