can handle string around 10,000. recursive function, and memory allocation is bottleneck