restructured check cmd exists