Improve debouncing algorithm