Resolving buffer overflow issue