exercise 9.5 : a bug fixed

return last rather than last + 1