fix out of memory for big string, based on atiqamjad comment