Wrap generated code in a block if necessary (closes #160)

Related to #160