refactored image loading