The stability and chemical reactivity of titanium nitride and titanium carbide