Refactor the index and abstract out to specific files
Merge from master