Move readState into State class, add some tests