Some of the code from Think Stats but the way I see it in C#