[Jay] Fix memory corruptions: buffer overflow and use of uninitialized value.