Using photochemistry to explain the formation and observation of C2 in comets