Code for simulations of type 2 and 3.