restructured.  analyzeImagesInBuffer is no longer a nested function