added startindex logic