Begin refactoring of images.py