Filter Function.

This is the most complicated function, therefore I would like to test it before it goes live.