Make flatten detect cycles in object being flattened