Refactor exec_findcmd a little