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.
Actually, I think `safely_flatten` would be even better.