fixed key sorting bug