query builder for dam attached to image gallery
bug fix