Reduce states, fix bugs