more debugging of algorithm