Clean ups, log variable setting, record promise that set variable.

Assorted preparations for the fix for RedMine 1492 (but the fix itself is still problematic).
Pushed for the sake of getting the "record which promise set a variable" change out where others can use it.