fixing iterator bug