updated closed region detecting algorithm