Improves the sort routine for State