Added some error/debugging functions so that any debugging/error output goes through stderr and not stdout