implement (nearly correctly) all of the algorithm, and add second heuristic test