Starting to work and pass tests. Fixed bug with index files ending up in wrong place.