Abstract out common code.