finished SP algorithm ood