Fixed Infinite Loop and -1 edge weight problem