Add error handling to handle missing queries and no queries at all.