some bug fixes to the to_string() method

Also tested using transform to wite to a new file