Added additional debugging to safe_write/read