added a solution to handle circular references