Modify filter function with validation