Fix calculate_level method