Changing line 156 from if(seg.on) to if(seg?.on) is an easy way to take care of the specific error in this screenshot. (I wouldn't be surprised if line 153 might also throw an error sometimes, depending on what data is, but since that comes first, you probably would have already seen that if so.)