Minor bug for networks with self-loops corrected.