Move more code into the popup