How to flatten highly recursive data structures for storage/retrieval [1]