Removed getEndIndex helper function, its functionality can be mimiced using indexOfSubstring