added code for opening and closing of blocks.