Fix and refactor addImageGallerHandler