Better debouncing algorithm