fix usage of next. don't use expensive type comparisons.