porting chap07's example