ENG-6229 Modified code to exit with correct error code