Refactor filter handling