Minor improvement in the next function.