mark code corresponding to Algorithm 3.1 in arXiv:1409.6100