Prevent Index Null

Move the code so that it detects before the index reaches a null
Trying to generate other cubes.

Try to generate new cubes after the current ones are positionned
Cubes are being generated after looping

Once the loop done new Cubes are beign generated. Cubes with one
dimension are not being place at the right position. THey start from
the second row when they should start on the first row. The cubes with
3 rows should have a slight glitch when they get  X O X the X should
move  and cover the gap but it is not. X -> O -X         O X X