Simplify to one loop

Only use one loop to compile 3D array, then do calculations using this.