Move filterProgram into a factory function.