better math, but still a mess