Fixing buffer overrun bug