changed int in size_t for large grid sizes