Added checking of overflow in magnetometer.