Refactor index()