Fix issue where query was not defined