Detect cyclic references to prevent infinite recursion.

Prevents panics from stack overflow with a heuristic to detect cycles.
Merge branch 'detect-cycles'

Conflicts:
	formatter.go
	formatter_test.go