fixes #16

bugs in variance calculation
optimizations