New approach to make endIndex optional