improved intersection of lines algorithm