Better graphing algorithm