changed trimFunction to preprocessFunction to be more robust