properly calculating galleryIndex :)