Question about number density of electrons
The 2 in your equation is the average number of mass units per electron. e.g. totally ionised carbon has 6 electrons and 12 mass units. In your formula, the mass of a proton is used as a mass unit (close enough in this case).

In your second equation $n_e^{-1/3}$ is an approximation for the inter-particle separation. This is an approximation and there is a small numerical factor that would need to be introduced in an accurate treatment.