minor changes to sorting