Nit: no one-line `if`-statements, please change to:
```
if (timeout) {
  clearTimeout(timeout);
}
```