Fix of envelope calculation bug