Factorization of the classical and the quantum S matrix and conservation laws