separating remote switch logic into new module

A refactor that went too long... This cleanup fixed several old problems
and identified several new ones. Onward.