Resource cleanup fixes.
Merge pull request #2 from anthonyu/cleanup_fixes

Resource cleanup fixes.