Refactoring of the popover hide method.