cleanup recv_packet() function