The purpose of your calculations may be clear to you, but it is perhaps not clear to others.
If you could include a few sentences clearly describing what the notebook is supposed to produce and include a sentence for each function stating what the possible inputs can be and another sentence stating what the function should produce that might help you and others more clearly see whether the code is correct or not. Please try to make those descriptions very simple and clear and still describe all possible cases for input and output.
I assume the function named average did not expect to be given input that would calculate a result 0/0. I cannot determine whether the input is incorrect or whether a result 0/0. should perhaps return 0.
I assume the function named insert did not expect to be given a first argument {}. I cannot determine whether the input is incorrect or whether when given a first argument of {} that it should return the value of grid unchanged.