Elements of Automata Theory