rewrote graphing code