horrible implementation of filterFunction