some extra sorting before the filter