fixed process.stdout error handling, ugly