Refactor Graphing function and add tests.