updated logic of finding the affected shapes