fixed double call + moved cmd[] outside the loop