NOJIRA:  A bit of refactoring in advance of some JS bug fixes;  should make subsequent commits easier to read