fixing line drawing algorithm