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.
Merge pull request #38 from gusennan/extract_error_printing

Extract error printing and exit into functions