clean up processing code and add time-averaging