Added inline documentation for the main socket handler