The quantum mechanical theory of environmental effects