Fix int() problem when the query has no results.
Clean up at the end.