some improvements on generated code