Correct bug in example code

Fixes #2598.