refactor index calc