add popup, and some refactoring