Fix Flatten

If the lowest keys in the dictionary were part of a list, they wouldn't
unflatten properly.