Fix detection of query