improve error reporting messages and use stderr