Add safety for some possible glitch

(based on commit 96ad6a8)

Signed-off-by: Xfurry <xfurry@scriptdev2.com>