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

Resource cleanup fixes.