refactored code slightly, need to add custom debounce.