Fix popover arrow

Fix to keep popover arrow inside the popover window. The calculations got a bit complicated.