Fix math issues