Put filter generation into a "core" function