Source: https://www.cs.swarthmore.edu/~fontes/cs46/20s/misc/Sipser-ch51-53.pdf