Some additions to the math functionality
More work on the math: fixes and improvements