Algorithm implemented, compiles but not tested. XXX: add API that plies susbt