Algebraic Theory of Automata