better iterator type detection