Refactor, make sockets like IPython does