Consolidate duplicate code.

Saves 494 minified bytes.