minor modification of sort