Fixed bugs which occurred while deleting directories