Close resources before return
Merge pull request #1 from gotimer/master

Close resources before return