diff() method moved to a independent helper function
Added optional string_io argument