Algorithm almost done