replaced std::cout with fprintf