Refactor graphing routines into separate file