Fix query problems