Added to_string function for debugging. Fixed some by-reference errors that were causing graphs to inadvertently share edges with each other.