fix the buffer corruption