fixing a problem with the heap for shortest distance and cleaning up some code