realized this algorithm doesn't work with cycles. will return to this later.