Free resources on error
Remove duplicate branch
Merge pull request #32 from mscdex/master

misc fixes