Fix resources not getting cleaned up.