changed variable index to start from zero