refactoring match image into method