fixes to algorithm 2, and proof of completeness