made sure no write happens after delete and file handle is closed
changed diagnostic system print to asserts.