created graphing function and refactored some of the code