memory related fixes