Theoretically I agree, but as a practical matter, I don't see how I can separate all the functions. This function is all about minimizing memory usage and time required to modify the image. Breaking the modifications into separate steps would probably have to be slower and/or use more memory.