Implementing left-factorization.