optimized by 'cmd()' function