Added error checking for really long queries.