finish sweep and prune algorithm