Use standard library math functions for final stat

Replace the calculation of mean and variance by their respective functions applied over a slice of the vector. IIRC those slices have copy semantics, but it is after the simulation ended so not time critical. It may give a memory usage spike though...

This shaved quite a few lines, but on the other hand I added blank lines in many parts to make the code pretier.