Move cmd into function.

No need to define it outside the function.