changed cmd to return a function