Improved handling socket events, optimized client