Refactored Graph class.

The Graph now uses a bag internally.