added debounce to the code