Improved filter script