changed token cleanup code slightly