Fix throwing of unknown and duplicate state errors and add tests.