Refactor filter generation.