Fixing errors in magnitude calculations