Isolate variable inside the promise chain

While investigating #576, @nullstyle suggested that we isolate the scope of some variables in registration to eliminate possible race conditions.