Optimize method by replacing .test to .indexOf