Some test code
Added missing newlines
Made log a little more robust
Replaced std::cout with log and ostringstream with format