Code for forthcoming paper