fixes #5182 Duplicate keys creating for key value field

Fixed the issue and pushed the code for review, please check it.