refactor code in index file