replace elements with same key

plus correctly calculate size()