cleaning up maths code