Fix illegal memory access