refactor and fix queue sorting for name fields and pending queue (bug 890177)