fix buffer undefined error