Resource cleanup fixes.

Resource cleanup fixes.