Abstracted out some socket logic