Refactor filters code slightly