fix order by issue for complex filter logic