STABLE VERSION: improved output file error checking. Also, error messages are now written to stderr and not stdout.