Fix errors in calculations.
Fix issue caused by incorrectly re-using uninitiallized value.