This line seems to be pretty error prone. Especially without any `assert()`s to give meaningful errors when the expected state doesn't exist.