prioritize_states() now uses a linear-time algorithm.