Fixed flatten error when removing directories