Refactored logic for creating popup into a separate method called in each event handler. Fixed bugs causing formatter to fail and preventing popup from being created.