Improve some of the mathematics