New maths library plus bug fixes