Fix that files are closed when reading is finished