Refactored socket state to be better encapsulated