Improved code generation for filters