Research code for the book