refactor to use Arrays.sort