A mostly working filter function. Brings my mac to it's knees