Added protection against duplicated keys in key-value-mapping

http://manage.dimagi.com/default.asp?80598#674919