Added checking before deleting directory