Patched illegal memory access and updated memcheck script to have valgrind check for memory errors.