moved socket handler function to a separate module