Refactoring for image click logic