Replaced cout with cerr for error message