Can someone explain the mosaics of the Hagia Sofia

The Hagia Sofia has all these different mosaics but they are from differnt eras.

I’m wondering when most of the mosaics were but in, and when emperors had their mosaics put in did they erase existing once’s or when it was built was their blank space left that was intended to be filled over time, because it seems like much later emperors have their mosaics included along with some of the much older ones?