refactor index macro