thesis_code_chap6