Code for simulating task switching behavior