better drawing algorithm