If any switches are async, the subsequent code will execute before
the switches are finished. This commit moves all that code to a new
function, and debounces the calls to onSwitch() so it only executes
once, after all the switches finish.
Fizes #72.