fix bugs and add more test case

bug was in updating a key to a new value