Fixes issue #45 - stack overflow serializing some cyclic graphs