Fixed Kruskals algorithm