# How does expansion of electron shells work?

1. How does it work? I've read that its about the similarity of the energy levels of $3d$ and $3p$, but shouldn't the electron shell $4s$ be filled before $3d$ if filled? So what is done with the $3d$?

2. I'd also like to know in what cases will atoms of elements expand their valence electrons? Which blocks or groups or periods do this?