exercises 5.7-10, reorganized code into chapters