Fixed a big bug in the sd calculation.