fixed index calculations
refactor
refactor