improved widget code generation