added next_token function