More bugfixing, and trimming of states.