1. Structure popup button visibility when ON/OFF
2. Some code cleanup