More fixes for graph element sorting. Now basically refuses to consider two elements equal unless they have matching ids.