Tried fixing bug in finding the best path