refactor index code