thesis_code_chap4