Changed debouncing method and added additional event handlers