update filter function to be more flexible