This is a first approximation. Doing this 100% efficiently is quite hard because it would require comparing the range currently in the disk buffer and the range impacted by the layer change. I suspect this will work fine for the foreseeable future