Fix a next state caching bug
Merge branch 'develop'