Faster implementation of filter. Leaving old method for performance testing