Fixed bugs in envelope generator related to resource sharing