fixed bug when inserting duplicate elements