Some efficiency improvements to filtering