Fixing range query, adding tests to support it.