Handle circular dependencies on serialization. Fixes #1