Fixed boundary cases on erode and dilate, assigning Cache when invalid