Just put the script in the map.
Provided hierarchy
Map <- put script here
blocks_stacked:
Monoblock_1
Monoblock_2
....
Monoblock_n
var current_block: ShapedBlock
Monoblock_1
Monoblock_2
...
var next_block: ShapedBlock
Monoblock_1
....
Let's say every block is consist of Monoblock. If current_block hit the bottom or another block, don't remove current_block. just add blocks to blocks_stacked one block by one block. and check row is full and pop it. Then set current_block = next_block and change the position of the current_block. After that, instance new block to the next_block. That should solve all the possible problems.