rewrite check command, handle error properly.