Added buildGallery function