Code for figure 2