code for paper: http://arxiv.org/abs/1301.2820