changing processfn logic starting on line 820