Correct popup code so that it runs after onready