tweaked formatting
Fixed bug in circular reference checking
Fixed another bug in the circular reference checking