Rationalise some repeated whiteboard JS code.