Modify your average function
average[a_, b_, c_, d_, main_] := Module[{total = 0, count = 0, x},
If[a =!= Null, x = main[[a[[1]], a[[2]]]]; If[x != 0, total = total + x ; count++]];
If[b =!= Null, x = main[[b[[1]], b[[2]]]]; If[x != 0, total = total + x ; count++]];
If[c =!= Null, x = main[[c[[1]], c[[2]]]]; If[x != 0, total = total + x ; count++]];
If[d =!= Null, x = main[[d[[1]], d[[2]]]]; If[x != 0, total = total + x ; count++]];
If[count==0, Print["average[",a,",",b,",",c,",",d,",",main,"] -> Error total/N[count]==",total,"/",N[count]]];
Ceiling[total/N[count]]
]
Modify your insert function
insert[miniums_, grid_, x_, y_] := Module[{maya = grid, profu, profd, noimp, r, j},
If[Length[Dimensions[miniums]]<2, Print["insert[",miniums,",",grid,",",x,",",y,"] -> Error miniums==",miniums]];
profu = Dimensions[miniums][[1]];
profd = Dimensions[miniums][[2]];
For[r = 1, r <= profu, r++,
For[j = 1, j <= profd, j++,
maya[[x + r, y + j]] = miniums[[r, j]];
]];
maya]
Remove the assignment to main inside your dsfractal function. Parameters to functions may not have their values changed inside the function. It does not appear that you are using the result of that assignment and so perhaps no other changes are needed to store the value returned from the call to your insert function.
Now when you evaluate the notebook you should see error messages indicating what needs to be corrected.