added a seperate function for #10 that ignores cycles.