Rename and factor out function

Rename validate_cmd to expand_cmd an factor it out in three new
functions.
Trivial style fix