Adding a check for the query failing