Fixes error with nonexistent cachedir.
 Fixes error when query returns 0 results.