Use stderr and proper exit codes

Print errors to stderr instead of to stdout and exit with status code 1 when an error is encountered.