Prevent indexOf + splice issues when indexOf returns -1.