Added optimising code for chap07