Protect against infinitely recursing flatten.

Flatten one step at a time until we're as flat as we can be, which prevents objects which break `flatten` from recursing infinitely. A workaround for #95.
I think `safe_flatten` would be a better name for this method.