updated implementation to detect potential reference cycle(s) within
entities. updated test cases