re-write State.java from scratch, testing as you go, until it seems to work for everything..