Modified any array that touches an image to be dynamically allocated,
	 instead of put on the stack. This mitigates a stack overflow
	 issue in the case of large images. Minor variable renaming and
	 other minor changes.