code rearrangment
change some std::cout to std::cerr