refactored filter & sort fns [ci skip]