reduced the number of processing in generate_pai().