fix some sorting issues