Refactored images.py