code from ch3