Extract error printing and exit into functions

This commit removes many of the os.Exit function calls in the code so
that if error printing should be changed on a global basis then there's
one place to do it.  Removes duplication.