cleanup socket state changes and somethingelse i don't remember