Fixed major bugs in disjoint set datastructure