Sockets redesigning (more concise, readable, and thread-safe)