Fixes some mathematical errors