remove unnecessary free
put the pending messages at the right place