Fixed range query issues