experiment with caching the state string (functools.lru_cache)
Optimize constructing the state string
merge