algorithm from the paper