Program now prioritizes shorter paths when distances are equal