Replaced direct stdout with buffering in a stringstream object.