added chapter8 code