minor optimization for bellman-ford
some refactorings + implemented AStar