correct nextKey in case of an error