Previous fix here didn't take into account the case where use can cancel the query (by pressing Esc).