Made the indexing of the file a function.