How and why the wave function collapses after a measurement