Algebraic theory of automata