Fix bug in plugin and cleanup example code