Algorithm mostly complete