These variables can all be moved into the if (index >= 0) condition. Or changed the condition to
```
if (index < 0)
  return InvalidParams;
```
right after loading the index.