functionally correct again
some refactoring to make the filter easier to read.
Passed fields instead of calclulating them each time.
Passed fields instead of calclulating them each time.