bug fix in quey writer