cleanup the template structure and normalize the blocks