Part 2 of state file bugfixes & error-checking.