you don't use num_messages here?! So why did you compute it in the first place and why does this function have this argument then?