fixed memory access bug

invalid pointer handling fixed, why did this not occur earlier?