Much better math.

Reduced my previous solution