Fix query ranges