added glitch protection