Fix bug with duplicate socket events on reconnect

To fix bug, restructured socket event handlers to follow proper pattern instead of declaring them inside the `connect` event.