fixed the negative variance bug