magnetometer code improvements