Fixed bug regarding index files and refactored some code.