More memory related fixes