fixed error reporting in all code to use fprintf to print to stderr