Correction on logging and change permissions before deleting