Code cleanup and fixes. More changes to popup.