Added an additional condition to an if statement in calcIndex