Adds init function and does more refactoring in Graph