Work on bad accesses and then memory leaks.

This cleans up the global cache of images stored above.