Add lots more error checking. Use EXIT{SUCCESS_FAILURE} instead of 0/1 in main. Be more consistent about use of exit versus return in main.