shadow: improve invalid region detection