DRY-ier JS version