fix bug that exit code was not set properly