optimize the code to get the next worker

Signed-off-by: Sébastien Boisvert <boisvert@anl.gov>