Refactor filter functions