move processing into a function in preparation for parallelization