Understanding degradation in lithium-ion and lithium-air batteries