restructure debounce code