added automatic optimization of the number of work messages to send