pig optimization script