Understanding degradation and improving stability of solution-processed organic and perovskite solar cells