Fixed leaking global variable.

Fixed bug in my last commit that caused all images to be the same as the first image