Fixing bugs found by static analysis
Merge pull request #180 from rlerdorf/master

Fix some bugs found by static analysis