Refactor for better filter handling