Architecturally better, although sligthly buggy, implementation of socket receiving.