Refactor Graph and create unit tests