       {i, [value]} when is_map(value) ->
         neg_i = "_" <> i
         case Map.fetch(deleted_map, neg_i) do
-          {:ok, [value2, 0, 0]} -> [{i, diff(value2, value)} | all_checked(tail, Map.delete(deleted_map, neg_i))]
+          {:ok, [value2, 0, 0]} -> [{i, do_diff(value2, value)} | all_checked(tail, Map.delete(deleted_map, neg_i))]
           :error -> [head | all_checked(tail, deleted_map)]
         end
       _ -> [head | all_checked(tail, deleted_map)]
     end
   end
 
-  defp check_map(list1) do
-    case Enum.split_while(list1, &split_underscore/1) do
-      {[], []} -> list1
-      {_, []} -> list1
+  defp do_diff(l1, l2) when is_list(l1) and is_list(l2) do
+    map1 = l1 |> Enum.with_index |> Enum.into(%{})
+    map2 = l2 |> Enum.with_index |> Enum.into(%{})
+    {rest_map2, new_list} = Enum.reduce(map1, {map2, %{}},
+      fn({k, i1}, {new_map2, acc}) ->
+        case Map.get(new_map2, k) do
+          nil -> {new_map2, Map.put(acc, "_"<><<i1+48>>, [k, 0, 0])}
+          ^i1 -> {Map.delete(new_map2, k), acc}
+          i2 -> {Map.delete(new_map2, k),
+                 Map.put(acc, "_"<><<i1+48>>, ["", i2, 3])}
+        end
+      end
+    )
+    new_list2 = Enum.reduce(rest_map2, new_list,
+      fn({k2, i3}, acc) ->
+        Map.put(acc, <<i3+48>>, [k2])
+      end
+    )
+    {_shift, new_list3} = Enum.reduce(new_list2, {0, new_list2}, fn
+      ({_ , [_, 0, 0]}, {shift_length, acc}) -> {shift_length+1, acc}
+      ({_, [_]}, {shift_length, acc}) -> {shift_length-1, acc}
+      ({<<"_", x>>, ["", y, 3]}, {shift_length, acc}) when (x-48)-y === shift_length ->
+        {shift_length, Map.delete(acc, <<"_", x>>)}
+      (_, {shift_length, acc}) -> {shift_length, acc}
+      end
+    )
+    case Enum.split_while(new_list3, &split_underscore/1) do
+      {[], []} -> new_list3
+      {_, []} -> new_list3
       {check, deleted} ->
         deleted_map = Enum.into(deleted, %{})
         all_checked(check, deleted_map)
     end
-  end
-
-  defp do_diff(l1, l2) when is_list(l1) and is_list(l2) do
-    map1 = Enum.with_index(l1) |> Enum.into(%{})
-    map2 = Enum.with_index(l2) |> Enum.into(%{})
-    {rest_map2, new_list} = Enum.reduce(map1, {map2, %{}},
-      fn({k, i1}, {new_map2, acc}) ->
-        case Map.get(new_map2, k) do
-          nil -> {new_map2, Map.put(acc, "_"<>to_string(i1), [k, 0, 0])}
-          ^i1 -> {Map.delete(new_map2, k), acc}
-          i2 -> {Map.delete(new_map2, k),
-                 Map.put(acc, "_"<>to_string(i1), ["", i2, 3])}
-        end
-      end
-    )
-    Enum.reduce(rest_map2, new_list,
-      fn({k2, i3}, acc) ->
-        Map.put(acc, to_string(i3), [k2])
-      end
-    )
-    |> Enum.to_list
-    |> check_shift(0)
-    |> check_map
     |> Enum.concat([{"_t", "a"}])
     |> Enum.into(%{})
   end

              v_diff2 = Map.delete(v_diff, "_t")
              v_map
              |> Enum.with_index
              |> Enum.map(fn({v, k}) -> {to_string(k),v} end)
              |> Enum.into(%{})
              |> do_patch_list(%{}, v_diff2, 0)
            false -> do_patch(v_map, v_diff)

          }
      end
      new_diff when is_map(new_diff) ->
        new_value = list2 |> Map.fetch!(si)
        |> do_patch(new_diff)
        {list2, Map.put(new_list2, si, new_value), true}
      false ->
