some refactor/fix for popup