Improved generated code (avoid duplicated code).