Performance improvements

I made some small performance improvements to the filtering process.