Fix to work when query exists