use exclusive file access and fix deletion handling