added handling of cyclic references