smarter popup positioning