fix debouncing

debounce function that responds to resize events, for better perf. also cleans up some duplicate code