Minor cleanup and fix socket callbacks.