Replacing SetTimeout and debouncing