added index checking