implemented smallest path algo