fix infinite loop when two or more keys were identical