updated code for ch 5, 6 and 9