use better algorithm to pull messages

Link: https://github.com/GeneAssembly/biosal/issues/310
Signed-off-by: Sébastien Boisvert <boisvert@anl.gov>