Sort modules and states.