Improve `_flatten()`.

Hello leaf,

Hopefully this should be faster and lighter on memory.
Remove a stray space.
Update socket.lua as well.
Merge pull request #1 from pygy/patch-1

Patch 1