make function to find regions work properly with flood-fill algorithm