made suggested changes to filtering function