Reduce stack memory size for layer mapping
the code declare useless multidimensional arrays at the beginning
we can make smaller arrays, with less dimensions inside the loops
it makes the stack demand much smaller, the runtime quicker and the code debugging much easier