WIP

- Moving the writer to subroutines
- Clean the code around the creation of file and paths
Fixed bug + added footer

Creating the index files we were using %s instead %d for the filename.