extract expanding into a function.

so we want use it elsewhere.