Better handling of duplicate keys and added a new LMDB foreach mechanism