Rearranged code for the book