changed the condition in the loop of the writeOutput function by adding a counter that counts the number of blocks that are in use at each moment