made C code generated more robust