Reorganizing code for the book