Fixed popup logic