page 640 isbn 978-1-84480-732-1 make sure you have the correct version of the book.
I think its because you are returning the i instead of retval.