improved stdout and error handling