added debugging around filewrite