Fixed segfault caused by overflowing memory accesses