Fix an issue where the state chain was incorrect and a state's
previous state would sometimes point to itself.