Fixed some bugs

Not yet tested, but does not chraches in a not cyclectic graph