Fixed smart positioning of popup