Better popup code (Should fix #45)