Fixed more mathematical errors

Wow, a lot of math...