Memory related fixes