rewrote logic and syntax of the debounce.