Incorporated @lefthandedgoat fix

Huge speedup in state retrieval.