Update shortest distance code.