modified sort func