Resets recursively, keeping track of children. Created tests, which pass. Computation terminates on graph cycles. Added comments.