draft translation of algorithm, no test