refactor index calc func