refactoring in image_gallery