Resistance switching mechanism in TiO2