memory management fixes