added some more mem management