Correction to the level calculation algorithm