Changed internal error handling and error messages, to better work in the context of a command-line tool.