general bug fixes on queries