Improve Socket Handling