Improve logic for show_large_gallery helper