Refactored image functions