Spotted and fixed an off-by-one bug in the example code