LSM303DLHC - Calibration, Pitch, Roll and Tilt Compensated Heading

From what I have read the second calibration with the correction values should bring combined bias closer to zero.

To get "Correction for combined scale factors" close to 1 i had to change nT from 51279 to 512.79.
Don't know if this is correct.

First calibration:

Second calibration with calibration data:

Xm_off = compass.m.x*0.080 -35.250093; //X-axis combined bias (Non calibrated data - bias)
Ym_off = compass.m.y*0.080 -138.764237; //Y-axis combined bias (Default: substracting bias)
Zm_off = compass.m.z*0.080 + 164.007726; //Z-axis combined bias

Xm_cal =  1.020574*Xm_off -0.083683*Ym_off + 0.009699*Zm_off; //X-axis correction for combined scale factors (Default: positive factors)
Ym_cal =  -0.083683*Xm_off + 1.029068*Ym_off +0.027500*Zm_off; //Y-axis correction for combined scale factors
Zm_cal =  0.009699*Xm_off + 0.027500*Ym_off + 0.980459*Zm_off; //Z-axis correction for combined scale factors