Added missing variable in buildGallery function