Refactored image code.