merged 2 versions, added multigallery support