Slight refactor

* Use a for loop instead of an unidiomatic do..while with a manual increment.
* Separate task acquisition from task dispatch.
* Don't use const for error event (one long-ass string fewer to remember).
* Check early for task validity.

Change-Id: I644b0a88521dc683d5cc1984585f24beae780352