Just put the script in the map.
Map <- put script here
var current_block: ShapedBlock
var next_block: ShapedBlock
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.