improved graphing code