improve friendlis  sorting function