Wrote thompson algorithm.