properly exit on error