improved deleteFile() method