Fixed segfault bug caused by improper grid initialization