Solved by ptrblck in post #2 
              
              
                Have a look at this manual implementation. 
Skimming through your code it looks like the variance calculation is unbiased in your case.