added check for index