Fix global leaks.
Fix different lint errors
Merge pull request #51 from despairblue/master

Fix global leaks and lint errors
Merge from upstream