Adapt the popover example, fix some related bugs