What is the function of a commutator in an electric motor?