Finished new version of filter script