removed global var, pass sockfd to functions