receive algorithm