Minor improvement to dictionary iteration