fixed issue where end block wasn't being removed