Custom sorting: consider sorting direction