fix query range and ordering