refactored socket logic into seperate file