Tentative fix for buffer overflow error, may be incorrect