fixed the math to avoid floating point lossy