Refactored image testing code