Exit eith proper code on error