finalised filter script