Refine algorithms: change to queuing a task for state change and fire events