refectoring script file, modify dynamic allocation error