bug fixing in query writer