Rounding error fixed, rewritten illogical variable assignment