Improved to_string method.