some refactoring
finally found a way to fix the menu popup close behavior