Bug fix for the filter function