Static code analysis fixes
Fixes after code review
Merge pull request #33 from karianna/master

Static code fixes + a resource leak fix, feel free to reject if mainly not useful.