Add some debug logs
Simplify File references to String references
Use a tmp file to update preferences