Prevent indexOf + splice issues when indexOf returns -1.

Changes:
- Prevent -1 indexOf + splice errors