A few memory related fixes.