improved popover function