finished chapter39 example