Fix freeing keys, add another test