simplified and fixed exit from the block loop.