Fix query issues