Removed bug in calcIndex function
fixed the calcIndex funtion for efficiency in the table