improved magnitude calculation.