compiles, but crashes when switching states