Improved example code

The example program now waits for window to be closed.