fix hidePopup bug, and refactoring