Added check for returned error when executing queries.