optimize recvfrom part of code