Smarter popup positioning