writes files nicely, template cfg in json too